package org.zhadoop.stream.cql.exception;

import org.zhadoop.streaming.exception.ErrorCode;
import org.zhadoop.streaming.exception.StreamingException;
import org.zhadoop.streaming.exception.StreamingRuntimeException;

/**
 * 语义分析异常
 * @author zwd
 *
 */
public class SemanticAnalyzerException extends ApplicationBuildException{

	/**
	 * 序列化
	 */
	private static final long serialVersionUID = -7127785425713551665L;

	public SemanticAnalyzerException(ErrorCode errorCode, String... errorArgs) {
		super(errorCode, errorArgs);
	}
	
	 /**
     * <默认构造函数>
     *
     */
    public SemanticAnalyzerException(Throwable cause, ErrorCode errorCode, String... errorArgs){
        super(cause, errorCode, errorArgs);
    }
    
    /**
     * <默认构造函数>
     * 仅供内部warp函数使用
     *
     */
    protected SemanticAnalyzerException(Throwable cause, String fullMessage, ErrorCode errorCode){
        super(cause, fullMessage, errorCode);
    }
	
    
    /**
     * 包装StreamingException
     *
     */
    public static SemanticAnalyzerException wrapStreamingException(StreamingException exception){
        return new SemanticAnalyzerException(exception.getCause(), exception.getMessage(), exception.getErrorCode());
    }

    /**
     * 包装StreamingException
     *
     */
    public static SemanticAnalyzerException wrapStreamingRunTimeException(StreamingRuntimeException exception){
        if(exception.getErrorCode() != null)
        {
            return new SemanticAnalyzerException(exception.getCause(), exception.getMessage(), exception.getErrorCode());
        }

        return new SemanticAnalyzerException(exception.getCause(), exception.getMessage(), ErrorCode.UNKNOWN_ERROR);
    }

}
